HAL PLAY initialization and configuration functions migration ¶
The goal of this page is to show how to migrate the Init sequence using STM32CubeMX2:
Open STM32CubeMX2 PLAY configuration panel.
Configure the SW layer HAL.
Configure the PLAY main features.
Configure the NVIC if the application requires the PLAY to be used in IT mode.
Generate the code.
HAL PLAY configuration panel ¶
Create a new project with the STM32CubeMX2, then start the initialization and the main configuration.
HAL PLAY main features configuration ¶
Configure the PLAY main features.
HAL PLAY GPIO configuration ¶
Configure gpio pins.
HAL PLAY EXTI configuration ¶
Configure the EXTI.
HAL PLAY NVIC configuration ¶
Configure the NVIC in case of an interrupt.
Generated PLAY initialization and de-initialization sequences ¶
The PLAY initialization sequence is generated in the
mx_play_init
function in the
mx_play.c
file under
$YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.
Related concepts:
|
Topic |
Code Snippet HAL1 |
Code Snippet HAL2 |
|---|---|---|
|
Handle declaration |
HAL_PLAY_HandleTypeDef hplay1;
|
hal_play_handle_t hPLAY1;
|
|
Initialization and configuration sequence |
static void MX_PLAY1_Init(void)
{
hplay1.instance = PLAY1;
if (HAL_PLAY_Init(&hplay1) != HAL_OK)
{
Error_Handler();
}
/* PLAY input configuration */
HAL_PLAY_IN_ConfTypeDef configINPUTs[1];
configINPUTs[0].source = HAL_PLAY1_IN_IN0_MUX0;
configINPUTs[0].mode = HAL_PLAY_EDGE_DETECTION_BYPASSED;
configINPUTs[0].min_pulse_width = 0;
if (HAL_PLAY_INPUT_SetConfig(&hplay1, configINPUTs, 1U) != HAL_OK)
{
Error_Handler();
}
/* PLAY LUT configuration */
HAL_PLAY_LUT_ConfTypeDef configLUTs[1];
/* LUT0 configuration */
configLUTs[0].lut = HAL_PLAY_LUT0;
configLUTs[0].truth_table = 0x00;
configLUTs[0].clk_gate_source = HAL_PLAY_LUT_CLK_GATE_OFF;
configLUTs[0].input_source[HAL_PLAY_LUT_INPUT0] = HAL_PLAY_LUT_INPUT_LUT0_OUT_REGISTERED;
configLUTs[0].input_source[HAL_PLAY_LUT_INPUT1] = HAL_PLAY_LUT_INPUT_SWTRIG0;
configLUTs[0].input_source[HAL_PLAY_LUT_INPUT2] = HAL_PLAY_LUT_INPUT_DEFAULT;
configLUTs[0].input_source[HAL_PLAY_LUT_INPUT3] = HAL_PLAY_LUT_INPUT_DEFAULT;
if (HAL_PLAY_LUT_SetConfig(&hplay1, configLUTs, 1U) != HAL_OK)
{
Error_Handler();
}
/* PLAY output configuration */
HAL_PLAY_OUT_ConfTypeDef configOUTPUTs[1];
/* Connect LUT0 (direct output) to PLAY output 0 */
configOUTPUTs[0].output_mux = HAL_PLAY_OUT0;
configOUTPUTs[0].lut_output = HAL_PLAY_LUT0_OUT_DIRECT;
if (HAL_PLAY_OUTPUT_SetConfig(&hplay1, configOUTPUTs, 1U) != HAL_OK)
{
Error_Handler();
}
EXTI_ConfigTypeDef exti_config;
/* EXTI line 64 is connected to PLAY1_OUT14 */
exti_config.Line = EXTI_LINE_64;
exti_config.Trigger = EXTI_TRIGGER_RISING;
if (HAL_EXTI_SetConfigLine(&hexti, &exti_config) != HAL_OK)
{
Error_Handler();
}
}
void HAL_PLAY_MspInit(HAL_PLAY_HandleTypeDef* hplay)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(hplay->instance==PLAY1)
{
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_PLAY1;
PeriphClkInitStruct.PLAY1ClockSelection = RCC_PLAY1CLKSOURCE_LSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_PLAY1_CLK_ENABLE();
__HAL_RCC_PLAY1APB_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
/**PLAY1 GPIO Configuration
PF3 ------> PLAY1_OUT0
PE9 ------> PLAY1_IN12
*/
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF14_PLAY1_OUT;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF14_PLAY1_IN;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
HAL_NVIC_SetPriority(PLAY1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(PLAY1_IRQn);
}
}
|
hal_play_handle_t *mx_play1_init(void)
{
HAL_RCC_PLAY1_EnableClock();
HAL_RCC_PLAY1APB_EnableClock();
if (HAL_PLAY_Init(&hPLAY1, HAL_PLAY1) != HAL_OK)
{
return NULL;
}
if (HAL_RCC_PLAY1_SetKernelClkSource(HAL_RCC_PLAY1_CLK_SRC_LSE) != HAL_OK)
{
return NULL;
}
/* PLAY input configuration */
hal_play_in_config_t in_config[1];
in_config[0].source = HAL_PLAY1_IN_IN0_MUX0;
in_config[0].mode = HAL_PLAY_EDGE_DETECTION_BYPASSED;
in_config[0].min_pulse_width = 0;
if (HAL_PLAY_INPUT_SetConfig(&hPLAY1, in_config, 1U) != HAL_OK)
{
return NULL;
}
/* PLAY LUT configuration */
hal_play_lut_config_t lut_config[1];
/* LUT0 configuration */
lut_config[0].lut = HAL_PLAY_LUT0;
lut_config[0].truth_table = 0x00;
lut_config[0].clk_gate_source = HAL_PLAY_LUT_CLK_GATE_OFF;
lut_config[0].input_source[HAL_PLAY_LUT_INPUT0] = HAL_PLAY_LUT_INPUT_LUT0_OUT_REGISTERED;
lut_config[0].input_source[HAL_PLAY_LUT_INPUT1] = HAL_PLAY_LUT_INPUT_SWTRIG0;
lut_config[0].input_source[HAL_PLAY_LUT_INPUT2] = HAL_PLAY_LUT_INPUT_DEFAULT;
lut_config[0].input_source[HAL_PLAY_LUT_INPUT3] = HAL_PLAY_LUT_INPUT_DEFAULT;
if (HAL_PLAY_LUT_SetConfig(&hPLAY1, lut_config, 1U) != HAL_OK)
{
return NULL;
}
/* PLAY output configuration */
hal_play_out_config_t out_config[1];
/* Connect LUT0 (direct output) to PLAY output 0 */
out_config[0].output_mux = HAL_PLAY_OUT0;
out_config[0].lut_output = HAL_PLAY_LUT0_OUT_DIRECT;
if (HAL_PLAY_OUTPUT_SetConfig(&hPLAY1, out_config, 1U) != HAL_OK)
{
return NULL;
}
hal_exti_config_t exti_config;
/* Initialize the EXTI for line 14 */
HAL_EXTI_Init(&hEXTI64, HAL_EXTI_LINE_64);
/* Set the trigger as RISING */
exti_config.trigger = HAL_EXTI_TRIGGER_RISING;
HAL_EXTI_SetConfig(&hEXTI64, &exti_config);
HAL_RCC_GPIOF_EnableClock();
HAL_RCC_GPIOE_EnableClock();
hal_gpio_config_t gpio_config;
/**PLAY1 GPIO Configuration
PF3 ------> PLAY1_OUT0
PE9 ------> PLAY1_IN12
*/
gpio_config.mode = HAL_GPIO_MODE_ALTERNATE;
gpio_config.output_type = HAL_GPIO_OUTPUT_PUSHPULL;
gpio_config.pull = HAL_GPIO_PULL_NO;
gpio_config.speed = HAL_GPIO_SPEED_FREQ_HIGH;
gpio_config.alternate = HAL_GPIO_AF_14;
HAL_GPIO_Init(HAL_GPIOF, HAL_GPIO_PIN_3, &gpio_config);
gpio_config.mode = HAL_GPIO_MODE_ALTERNATE;
gpio_config.output_type = HAL_GPIO_OUTPUT_PUSHPULL;
gpio_config.pull = HAL_GPIO_PULL_DOWN;
gpio_config.speed = HAL_GPIO_SPEED_FREQ_HIGH;
gpio_config.alternate = HAL_GPIO_AF_14;
HAL_GPIO_Init(HAL_GPIOE, HAL_GPIO_PIN_9, &gpio_config);
HAL_CORTEX_NVIC_SetPriority(PLAY1_IRQn, HAL_CORTEX_NVIC_PREEMP_PRIORITY_0, HAL_CORTEX_NVIC_SUB_PRIORITY_0);
HAL_CORTEX_NVIC_EnableIRQ(PLAY1_IRQn);
return &hPLAY1;
}
|
|
Deinitialization sequence |
void MX_PLAY_DeInit(void)
{
if (HAL_PLAY_DeInit(&hplay1) != HAL_OK)
{
Error_Handler();
}
}
void HAL_PLAY_MspDeInit(HAL_PLAY_HandleTypeDef* hplay)
{
if(hplay->instance==PLAY1)
{
__HAL_RCC_PLAY1_CLK_DISABLE();
__HAL_RCC_PLAY1APB_CLK_DISABLE();
/* De-initialize all GPIO pins associated with PLAY1 */
HAL_GPIO_DeInit(GPIOF, GPIO_PIN_3);
HAL_GPIO_DeInit(GPIOE, GPIO_PIN_9);
/* PLAY1 interrupt DeInit */
HAL_NVIC_DisableIRQ(PLAY1_IRQn);
}
}
|
void mx_play1_deinit(void)
{
HAL_PLAY_DeInit(&hPLAY1);
HAL_RCC_PLAY1_DisableClock();
HAL_RCC_PLAY1APB_DisableClock();
HAL_RCC_PLAY1_Reset();
HAL_RCC_PLAY1APP_Reset();
/* De-initialize all GPIO pins associated with PLAY1 */
HAL_GPIO_DeInit(HAL_GPIOF, HAL_GPIO_PIN_3);
HAL_GPIO_DeInit(HAL_GPIOE, HAL_GPIO_PIN_9);
/* De-initialize the EXTI for line64 */
HAL_EXTI_DeInit(&hEXTI64);
HAL_CORTEX_NVIC_DisableIRQ(PLAY1_IRQn);
}
|
|
IRQ handle function |
void PLAY1_IRQHandler(void)
{
HAL_PLAY_IRQHandler(&hplay1);
}
|
void PLAY1_IRQHandler(void)
{
HAL_PLAY_IRQHandler(&hPLAY1);
HAL_EXTI_IRQHandler(&hexti);
}
|